<template>
  <div class="info-right">
    <div class="eq-right-top">
      <div class="eq-right-top-title">
        <img src="../../../assets/images/home-page/eq-right.png" alt="" />
        设备信息
      </div>
      <div class="eq-right-top-item">
        <div class="tab-switcher">
          <div class="tab-headers">
            <div
              class="button"
              v-for="(tab, index) in tabs"
              :key="index"
              :class="{ active: activeIndex === index }"
              @click="switchTab(index)"
            >
              {{ tab }}
            </div>
          </div>
          <div class="tab-content">
            <div v-if="activeIndex === 0" class="tab-i-content">
              <div v-for="(item, index) in contentList" class="tab-i-c-box">
                <span class="tab-lab">{{ item.attrName }}：</span>
                <span class="tab-value">{{ item.attrVal }}</span>
              </div>
            </div>
            <div v-if="activeIndex === 1" class="tab-i-content-g">
              <div class="tab-g-c-b">
                <div v-for="(item, index) in alarmList" class="tab-g-c-box" @click="showDetails(item, index)">
                  <div class="t-g-c-img"><img :src="alarmIcon(item.alarmLevel)" alt="" /></div>
                  <div class="t-g-c-box" :class="`alarm-level-${item.alarmLevel}`"
                    ><span class="tab-lab">{{ item.alarmDesc }}：</span>
                    <span class="tab-value">{{ item.createTime }}</span>
                  </div>
                </div>
              </div>

              <div class="tab-i-btn-box">
                <div></div>
                <div class="tab-i-btn" @click="canChange"> 告警历史 </div>
              </div>
              <div class="eq-r-t-i-title">
                <span class="eq-dio"></span>
                <span class="eq-d-title">详情</span>
              </div>
              <div class="tab-content-box-d">
                <div class="tab-i-content">
                  <div class="tab-i-c-box">
                    <span class="tab-lab">设备名称：</span>
                    <span class="tab-value">{{ detailsObj.deviceName }}</span>
                  </div>
                  <div class="tab-i-c-box">
                    <span class="tab-lab"> 来源系统：</span>
                    <span class="tab-value">{{ detailsObj.alarmSystem }}</span>
                  </div>
                  <div class="tab-i-c-box">
                    <span class="tab-lab"> 信号类型：</span>
                    <span class="tab-value">{{ detailsObj.pointName }}</span>
                  </div>
                  <div class="tab-i-c-box">
                    <span class="tab-lab"> 等级：</span>
                    <span class="tab-value" v-if="detailsObj.alarmLevel == '1'">一般</span>
                    <span class="tab-value" v-if="detailsObj.alarmLevel == '2'">严重</span>
                    <span class="tab-value" v-if="detailsObj.alarmLevel == '3'">危急</span>
                  </div>
                  <div class="tab-i-c-box">
                    <span class="tab-lab"> 告警时间：</span>
                    <span class="tab-value">{{ detailsObj.createTime }}</span>
                  </div>
                  <div class="tab-i-c-box">
                    <span class="tab-lab"> 处理状态：：</span>
                    <span class="tab-value" v-if="detailsObj.alarmStatus == '0'">未处理</span>
                    <span class="tab-value" v-if="detailsObj.alarmStatus == '1'">已处理</span>
                  </div>
                  <div class="tab-i-c-box">
                    <span class="tab-lab"> 处理内容：</span>
                    <span class="tab-value">{{ detailsObj.alarmContent }}</span>
                  </div>
                </div>
              </div>
            </div>

            <div v-if="activeIndex === 2" class="tab-i-content">
              <div v-for="(item, index) in runList" class="tab-i-c-box-t">
                <span class="tab-lab">{{ item.atrrName }}</span>
                <span class="tab-value">{{ item.pointVal }}</span>
              </div>
            </div>
          </div>
        </div>
        <!-- <div class="info-right-bottom">
          <div class="i-r-b-box">
            <div class="i-r-b-left">
              <img
                @click="toMonitor(2)"
                class="right-img"
                src="../../../assets/images/home-page/info-right.png"
                alt=""
              />
              <span>监测/监控</span>
              <img class="sxt-img" src="../../../assets/images/home-page/sxt.png" alt="" />
            </div>
            <div class="i-r-b-right"> 拆解 </div>
          </div>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script setup>
  import { onMounted, ref } from 'vue';
  import { busDeviceAlarmInfo, getDevicePointDetail } from '@/api/auth/ledger.js';
  import hong from '@/assets/images/home-page/gj-hong.png';
  import huang from '@/assets/images/home-page/gj-huang.png';
  import lan from '@/assets/images/home-page/gj-huang.png';
  const emit = defineEmits();
  const props = defineProps(['contentList', 'runList']);
  const activeIndex = ref(0); // 默认显示第一个选项卡
  const tabs = ['台账', '告警', '运行'];
  const alarmList = ref([]);
  const detailsObj = ref({});
  const params1 = ref({
    alarmContent: '',
    alarmDesc: '',
    alarmLevel: '',
    alarmStatus: '',
    alarmSystem: '',
    deviceName: '',
    orderByDesc: '',
    pageNum: 0,
    pageSize: 20,
    pointId: '',
    pointName: ''
  });
  const toMonitor = (a) => {
    emit('toMonitor', a);
  };

  function alarmIcon(level) {
    const icons = {
      1: lan,
      2: huang,
      3: hong
    };
    return icons[level] || icons['3']; // 默认图标
  }
  function showDetails(item, index) {
    console.log('res', item, index);
    detailsObj.value = item;
  }
  const getBusDeviceAlarmInfo = () => {
    busDeviceAlarmInfo(params1.value).then((res) => {
      alarmList.value = res.data.data;
      console.log('res', res);
    });
  };

  function switchTab(index) {
    activeIndex.value = index;
    if (index === 1) {
      getBusDeviceAlarmInfo();
    }
    emit('switchTab', index);
  }

  onMounted(() => {});
  // 确保在组件卸载时销毁图表实例
  onUnmounted(() => {});
</script>

<style lang="scss" scoped>
  .info-right {
    width: 360px;
    position: absolute;
    top: 120px;
    right: 18px;
    z-index: 999;
    .eq-right-top {
      width: 100%;
      // margin-top: 15px;
      .eq-right-top-title {
        width: 100%;
        height: 33px;
        background: rgba(10, 39, 82, 1);
        display: flex;
        align-items: center;
        color: #fff;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 16px;
        img {
          width: 20px;
          height: 21px;
          margin: 0 5px 0 10px;
        }
      }
      .eq-right-top-item {
        // height: 504px;
        width: 100%;
        background: rgba(5, 30, 67, 0.6);
        height: 76.2vh;
        .tab-switcher {
          width: 327px;
          margin: 0 auto;
          .tab-headers {
            width: 327px;
            height: 32px;
            background-image: url('../../../assets/images/home-page/info-bg.png');
            background-size: 100% 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .button {
              cursor: pointer;
              width: 33%;
              height: 100%;
              font-family: PingFang SC;
              font-size: 14px;
              color: #ffffff;
              display: flex;
              align-items: center;
              justify-content: center;
              &.active {
                background-image: url('../../../assets/images/home-page/info-tab.png');
                background-size: 100% 100%;
              }

              &:hover {
                opacity: 0.95;
              }
            }
          }

          .tab-content {
            width: 98%;

            .tab-i-content {
              width: 100%;
              height: 66vh;
              background-color: rgba(5, 30, 67, 0.65);
              margin: 6px auto 0 5px;
              border: 1px solid #1f4996;
              .tab-i-c-box {
                width: 100%;
                display: flex;
                align-items: center;
                padding: 8px 0;
                .tab-lab {
                  width: 35%;
                  font-family: PingFang SC;
                  font-size: 12px;
                  color: rgba(255, 255, 255, 0.8);
                  text-align: right;
                }
                .tab-value {
                  width: 65%;
                  font-family: PingFang SC;
                  font-size: 12px;
                  color: #ffffff;
                }
              }
              .tab-i-c-box-t:nth-child(2n) {
                background-color: rgba(33, 66, 124, 0.3);
              }
              .tab-i-c-box-t {
                width: 100%;
                display: flex;
                align-items: center;
                height: 36px;
                background-color: rgba(10, 138, 206, 0.3);
                .tab-lab {
                  width: 40%;
                  font-family: PingFang SC;
                  font-size: 16px;
                  color: rgba(255, 255, 255, 0.8);
                  margin-left: 10px;
                  font-size: 12px;
                }
                .tab-value {
                  width: 60%;
                  font-family: PingFang SC;
                  font-size: 16px;
                  color: #ffffff;
                  font-size: 12px;
                  text-align: right;
                  margin-right: 10px;
                }
              }
              // padding: 20px;
              // border: 1px solid #ccc;
              // display: none;
            }
          }
          .tab-i-content-g {
            .tab-g-c-b {
              width: 100%;
              height: 30vh;
              margin: 6px auto 0 auto;
              overflow-y: scroll;
              .tab-g-c-box {
                width: 308px;
                height: 65px;
                background-image: url('../../../assets/images/home-page/gj-bg.png');
                background-size: 100% 100%;
                display: flex;
                align-items: center;
                margin: 0 auto;
                margin-bottom: 5px;
                &:hover {
                  opacity: 0.9;
                  cursor: pointer;
                }
                .t-g-c-box {
                  span {
                    display: block;
                    font-family: PingFang SC;
                    font-size: 14px;
                  }
                  .tab-value {
                    margin-top: 10px;
                  }
                }
                .alarm-level-1 {
                  .tab-lab {
                    color: #ffc148; /* 等级1的描述颜色 */
                  }
                }

                .alarm-level-2 {
                  .tab-lab {
                    color: green; /* 等级2的描述颜色 */
                  }
                }

                .alarm-level-3 {
                  .tab-lab {
                    color: #f2634f; /* 等级3的描述颜色 */
                  }
                }

                .alarm-level-1 {
                  .tab-value {
                    color: #ffc148; /* 等级1的时间颜色 */
                  }
                }

                .alarm-level-2 {
                  .tab-value {
                    color: green; /* 等级2的时间颜色 */
                  }
                }

                .alarm-level-3 {
                  .tab-value {
                    color: #f2634f; /* 等级3的时间颜色 */
                  }
                }
                .t-g-c-img {
                  width: 29px;
                  height: 28px;
                  margin: 0 20px;
                  img {
                    width: 100%;
                    height: 100%;
                  }
                }
              }
            }
            .tab-i-btn-box {
              width: 96%;
              display: flex;
              justify-content: space-between;
              margin: 10px auto 0 auto;
              .tab-i-btn {
                width: 80px;
                height: 30px;
                background-image: url('../../../assets/images/home-page/tubiao-bg.png');
                background-size: 100% 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                font-family: PingFang SC;
                font-size: 12px;
                color: #ffffff;
                // margin: 10px auto 0 auto;
                cursor: pointer;
                &:hover {
                  opacity: 0.95;
                }
              }
            }
            .eq-r-t-i-title {
              display: flex;
              align-items: center;
              padding-bottom: 10px;
              .eq-dio {
                width: 8px;
                height: 8px;
                background: #19db3c;
                border-radius: 50%;
              }
              .eq-d-title {
                font-family: PingFang SC;
                font-weight: bold;
                font-size: 14px;
                color: #ffffff;
                text-shadow: 0px 2px 3px rgba(0, 0, 0, 0.5);
                margin-left: 5px;
              }
            }
            .tab-content-box {
              width: 98%;
              height: 30vh;
              background-color: rgba(5, 30, 67, 0.65);
              margin: 6px auto 0 auto;
              border: 1px solid #1f4996;
              .tab-i-content {
                width: 100%;
                height: 80%;
                overflow-y: scroll;
                .tab-i-c-box:nth-child(2n) {
                  background-color: rgba(33, 66, 124, 0.3);
                }
                .tab-i-c-box {
                  width: 100%;
                  display: flex;
                  align-items: center;
                  height: 36px;
                  background-color: rgba(10, 138, 206, 0.3);
                  .tab-lab {
                    width: 40%;
                    font-family: PingFang SC;
                    font-size: 16px;
                    color: rgba(255, 255, 255, 0.8);
                    margin-left: 5px;
                    font-size: 12px;
                  }
                  .tab-value {
                    width: 60%;
                    font-family: PingFang SC;
                    font-size: 16px;
                    color: #ffffff;
                    font-size: 12px;
                  }
                }
                // padding: 20px;
                // border: 1px solid #ccc;
                // display: none;
              }
            }
          }
          .tab-content-box-d {
            width: 98%;
            background-color: rgba(5, 30, 67, 0.65);
            border: 1px solid #1f4996;
            margin: 0 auto;
            .tab-i-content {
              width: 100%;
              height: 80%;
              margin: 0 auto;
              .tab-i-c-box:nth-child(2n) {
                background-color: rgba(33, 66, 124, 0.3);
              }
              .tab-i-c-box {
                width: 100%;
                display: flex;
                align-items: center;
                height: 36px;
                background-color: rgba(10, 138, 206, 0.3);
                .tab-lab {
                  width: 30%;
                  font-family: PingFang SC;
                  font-size: 16px;
                  color: rgba(255, 255, 255, 0.8);
                  margin-left: 5px;
                  font-size: 12px;
                }
                .tab-value {
                  width: 70%;
                  font-family: PingFang SC;
                  font-size: 16px;
                  color: #ffffff;
                  font-size: 12px;
                }
              }
              // padding: 20px;
              // border: 1px solid #ccc;
              // display: none;
            }
          }
        }
        .info-right-bottom {
          width: 327px;
          margin: 0 auto;

          .i-r-b-box {
            width: 98%;
            background-color: rgba(5, 30, 67, 0.65);
            border: 1px solid #1f4996;
            height: 41px;
            margin: 6px auto 0 auto;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .i-r-b-left {
              width: 50%;
              display: flex;
              align-items: center;
              justify-content: space-around;
              .right-img {
                width: 13.3px;
                height: 15px;
                cursor: pointer;
                &:hover {
                  opacity: 0.95;
                }
              }
              .sxt-img {
                width: 16.2px;
                height: 18px;
              }
              span {
                font-family: PingFangSC;
                font-weight: 400;
                font-size: 14px;
                color: #ffffff;
              }
            }
            .i-r-b-right {
              width: 15%;
              font-family: PingFangSC;
              font-weight: 400;
              font-size: 14px;
              color: #69feda;
              cursor: pointer;
              &:hover {
                opacity: 0.95;
              }
            }
          }
        }
      }
    }
  }
</style>
